﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using HinduAlmanac.CalenderProper;
using System.Xml.Linq;
using System.Linq;
using System.Windows.Media.Imaging;

namespace HinduAlmanac.ViewModels
{
    public class CalendarMethods
    {
        XDocument xdoc = null;
        public List<Months> LoadMonthsInListPicker()
        {
            List<Months> objMonthsList = new List<Months>();
            objMonthsList.Add(new Months() { MonthId = 1, MonthName = "January" });
            objMonthsList.Add(new Months() { MonthId = 2, MonthName = "Febraury" });
            objMonthsList.Add(new Months() { MonthId = 3, MonthName = "March" });
            objMonthsList.Add(new Months() { MonthId = 4, MonthName = "April" });
            objMonthsList.Add(new Months() { MonthId = 5, MonthName = "May" });
            objMonthsList.Add(new Months() { MonthId = 6, MonthName = "June" });
            objMonthsList.Add(new Months() { MonthId = 7, MonthName = "July" });
            objMonthsList.Add(new Months() { MonthId = 8, MonthName = "August" });
            objMonthsList.Add(new Months() { MonthId = 9, MonthName = "September" });
            objMonthsList.Add(new Months() { MonthId = 10, MonthName = "October" });
            objMonthsList.Add(new Months() { MonthId = 11, MonthName = "November" });
            objMonthsList.Add(new Months() { MonthId = 12, MonthName = "December" });

            return objMonthsList;
        }
        public CalenderData Calenderdata(DateTime dt)
        {
            CalenderData objcaldata = new CalenderData();
            xdoc = XDocument.Load("AppData/CalenderDetails/Pancangam.xml");
            var callist = from i in xdoc.Descendants("day")
                          where i.Attribute("date").Value.ToString() == dt.ToShortDateString()
                          select i;
            foreach (var item in callist)
            {

                objcaldata.WeekDay = item.Element("wd").Value;
                objcaldata.Tidi = item.Element("t").Value;
                objcaldata.Nakshatram = item.Element("n").Value;

            }
            return objcaldata;
        }
        public List<CalenderData> GetVajram(DateTime dt)
        {
            List<CalenderData> objcalvjrmlist = new List<CalenderData>();
            xdoc = XDocument.Load("AppData/CalenderDetails/Pancangam.xml");
            var varque = from i in xdoc.Descendants("day") 
                         where i.Attribute("date").Value.ToString() == dt.ToShortDateString() 
                         select i;
            foreach (var varj in varque.Elements("v").Elements())
            {
                CalenderData objvar = new CalenderData();
                objvar.Varjam = varj.Value.ToString();
                objcalvjrmlist.Add(objvar);
            }
            return objcalvjrmlist;
        }
        public List<CalenderData> GetDurmurtham(DateTime dt)
        {
            List<CalenderData> objcaldurm = new List<CalenderData>();
            xdoc = XDocument.Load("AppData/CalenderDetails/Pancangam.xml");
            var dur = from i in xdoc.Descendants("day")
                      where i.Attribute("date").Value.ToString() == dt.ToShortDateString()
                      select i;
            foreach (var durmo in dur.Elements("d").Elements())
            {
                CalenderData objdur = new CalenderData();
                objdur.Durm = durmo.Value.ToString();
                objcaldurm.Add(objdur);
            }
            return objcaldurm;
        }
        public List<FestivalProper> GetMonthId(int monthid)
        {
            List<FestivalProper> objFestList = new List<FestivalProper>();
            XDocument xdoc = XDocument.Load("AppData/CalenderDetails/Festivals.xml");
            var festList = from f in xdoc.Descendants("festival")
                           where Convert.ToDateTime(f.Element("date").Value).Month == monthid
                           select f;
            
            foreach (var fest in festList)
            {
                FestivalProper objFest = new FestivalProper();
                BitmapImage objbitmapimage = new BitmapImage();
                objbitmapimage.UriSource = (new Uri(fest.Element("image").Value, UriKind.Relative));
                objFest.Imagelistfest = objbitmapimage;
                objFest.FId = fest.Attribute("id").Value;
                objFest.FName = fest.Element("name").Value;
                objFest.MonthName = fest.Element("date").Value;
                objFestList.Add(objFest);
            }
            return objFestList;
        }
        public FestivalProper GetFestDescription(string festid)
        {
            FestivalProper objfestdata = new FestivalProper();
            XDocument xdoc = null;
            xdoc = XDocument.Load("AppData/CalenderDetails/Festivals.xml");
            var festDetails = from i in xdoc.Descendants("festival")
                              where i.Attribute("id").Value.ToString() == festid
                              select i;
            foreach (var festd in festDetails)
            {
                
                BitmapImage objbitmapimage = new BitmapImage();
                objbitmapimage.UriSource = new Uri(festd.Element("image").Value, UriKind.Relative);
                objfestdata.FestImage= objbitmapimage;
                objfestdata.FName = festd.Element("name").Value;
                objfestdata.FDate = festd.Element("date").Value;
                objfestdata.FestDes = festd.Element("description").Value;

            }
            return objfestdata;
        }
    }
}
